package com.zx.practice03;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Dome03 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
        Class clz = Class.forName("com.zx.pojo.Person");
        Method getAge = clz.getDeclaredMethod("getAge",null);
        getAge.setAccessible(true);
        Object age = getAge.invoke(null,null);
        System.out.println(age);

        Method silentMethod = clz.getDeclaredMethod("silentMethod",null);
        silentMethod.setAccessible(true);
        Object person = clz.newInstance();
        silentMethod.invoke(person,null);

        Method setName = clz.getDeclaredMethod("setName", String.class);
        setName.setAccessible(true);
        setName.invoke(person,"蜘蛛侠");
        Object getName = clz.getDeclaredMethod("getName",null).invoke(person);
        System.out.println(getName);
    }
}
